package com.turnengine.client.global.announcement.command.gwt;

import static com.javabi.common.dependency.DependencyFactory.getDependency;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.javabi.codebuilder.generated.gwt.IGeneratedRemoteServiceServlet;
import com.javabi.command.IExecutableCommandResponse;
import com.javabi.command.errorcode.gwt.GwtErrorCodeException;
import com.javabi.command.executor.ICommandExecutorService;
import com.turnengine.client.global.announcement.command.PostAnnouncement;
import com.turnengine.client.global.game.enums.GameLevel;

/**
 * The Post Announcement Servlet.
 */
public class PostAnnouncementServlet extends RemoteServiceServlet implements IGeneratedRemoteServiceServlet, PostAnnouncementService {

	public int postAnnouncement(long loginId, int gameLevelId, GameLevel gameLevel, String subject, String body) throws GwtErrorCodeException {
		PostAnnouncement command = new PostAnnouncement(loginId, gameLevelId, gameLevel, subject, body);
		ICommandExecutorService service = getDependency(ICommandExecutorService.class);
		IExecutableCommandResponse<Integer> response = service.execute(command);
		if (response.hasErrors()) {
			throw new GwtErrorCodeException(response);
		}
		return response.getReturnValue();
	}
}
